import Types from '../types'
import {apiUrl} from "../../../config";




/**
 * 获取老师列表
 *
 */
export function fetchCourseTeachers(params){
  return dispatch => {
    let url = `${apiUrl}/arrangeClassCourse/getTeacherList?${params}`;
    console.log(url)
    fetch(url, {
      method: "GET",
      headers: {
        'token': '2c9eeeb789024442b185ed7854e84fa6',
      },
    }).then(res => {
      console.log(res);
      return res.json();
    }).then((data) => {
      console.log(data)
      dispatch({
        type: Types.COURSE_TEACHER_LOAD_SUCCESS,
        courseTeacher: data.obj,
      })
    }).catch(error => {
      console.log(error)
      dispatch({
        type: Types.COURSE_TEACHER_LOAD_FAIL,
        error
      })
    })
  }
}


/**
 * 获取学生课程表
 *
 */
export function fetchCourseSchedules(params){
  return dispatch => {
    let url = `${apiUrl}/arrangeClassCourse/getSchoolTimetable?${params}`;
    console.log(url)
    fetch(url, {
      method: "GET",
      headers: {
        'token': '2c9eeeb789024442b185ed7854e84fa6',
      },
    }).then(res => {
      console.log(res);
      return res.json();
    }).then((data) => {
      console.log(data)
      dispatch({
        type: Types.COURSE_SCHEDULE_LOAD_SUCCESS,
        courseSchedule: data.obj,
      })
    }).catch(error => {
      console.log(error)
      dispatch({
        type: Types.COURSE_SCHEDULE_LOAD_FAIL,
        error
      })
    })
  }
}


/**
 * 获取公告
 *
 */
export function fetchCourseNotices(params){
  return dispatch => {
    let url = `${apiUrl}/notice/getNoticeList?${params}`;
    console.log(url)
    fetch(url, {
      method: "GET",
      headers: {
        'token': '2c9eeeb789024442b185ed7854e84fa6',
      },
    }).then(res => {
      console.log(res);
      return res.json();
    }).then((data) => {
      console.log(data)
      dispatch({
        type: Types.COURSE_NOTICE_LOAD_SUCCESS,
        courseNotices: data.obj,
      })
    }).catch(error => {
      console.log(error)
      dispatch({
        type: Types.COURSE_NOTICE_LOAD_FAIL,
        error
      })
    })
  }
}